<%--
  Created by IntelliJ IDEA.
  User: 懒瑶瑶
  Date: 2022/5/23
  Time: 19:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加家庭联系关系</title>
    <%--    引入css、js--%>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/ajaxForm.js"></script>
    <script>
        layui.use(['form', 'laydate', 'layer'], function () {
            var form = layui.form, laydate = layui.laydate, layer = layui.layer;
            //定义自定义验证规则
            form.verify({
                v_notallnum:function (val,item) {
                    if (/^\d+\d+\d$/.test(val)){
                        return "名称不能全为数字"
                    }
                },
            });
            //监听表单提交
            form.on('submit(formBtn)', function () {
                var formData = new FormData($("#form1")[0]);
                $.ajax({
                    url:'${pageContext.request.contextPath}/emp/addfamily',
                    type : 'POST',
                    data : formData,
                    cache: false,
                    async: false,
                    processData : false,  //必须false才会避开jQuery对 formdata 的默认处理
                    contentType : false,  //必须false才会自动加上正确的Content-Type
                    mimeType:"multipart/form-data",

                    success:function(data){
                        layer.msg('添加成功！',{icon:6,offset:"auto",time:2000});//提示框
                        setTimeout(function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);//关闭弹出层
                            parent.location.reload();//重新加载父页面表格
                        }, 2100);
                    }
                });
                return false;
            });
        });
    </script>
</head>
<body>
<form class="layui-form" id="form1"  lay-filter="form1" enctype="multipart/form-data" >
    <%--    添加数据--%>
    <input type="hidden" name="empId" value="${empId}">
    <%--    联系人名称--%>
    <div class="layui-form-item">
        <label class="layui-form-label"  style="width: 150px">联系人名称：</label>
        <div class="layui-input-inline">
            <input type="text" name="contactName" class="layui-input" placeholder="请输入联系人名称" lay-verify="required|v_notallnum"/>
        </div>
        <span style="font-size: 10px;color: red">※</span>
    </div>
    <%--    与员工关系--%>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 150px" >与员工关系：</label>
        <div class="layui-input-inline">
            <input type="text" name="relationship" class="layui-input" placeholder="父子/母女/兄弟等" lay-verify="required"/>
        </div>
        <span style="font-size: 10px;color: red">※</span>
    </div>
    <%--    联系电话--%>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 150px">联系电话：</label>
        <div class="layui-input-inline">
            <input type="text" id="datetime" name="phone" class="layui-input" lay-verify="required|phone"/>
        </div>
        <span style="font-size: 10px;color: red">※</span>
    </div>
    <%--  说明--%>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width: 150px">说明：</label>
        <div class="layui-input-inline">
            <textarea name="remark" class="layui-input" style="width: 200px;height: 100px" placeholder="说明字数0-500字"></textarea>
        </div>
    </div>
    <%--按钮--%>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="formBtn">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
</html>
